<script setup lang="ts">
import { ref } from "vue";
import { usePosition } from "@/views/system/position/utils/hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";

import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import AddFill from "@iconify-icons/ri/add-circle-line";

defineOptions({
  name: "SystemPosition"
});

const formRef = ref();
const {
  form,
  loading,
  columns,
  dataList,
  pagination,
  onSearch,
  resetForm,
  openDialog,
  handleDelete,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange
} = usePosition();
</script>

<template>
  <div class="main">
    <el-form ref="formRef" :inline="true" :model="form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]">
      <el-form-item label="岗位名称：" prop="keyword">
        <el-input v-model="form.keyword" placeholder="请输入岗位名称" clearable class="!w-[180px]" />
      </el-form-item>

      <el-form-item label="所属部门：" prop="deptId">
        <el-cascader v-model="form.deptId" :options="form.deptOptions" :props="{
          value: 'id',
          label: 'deptName',
          emitPath: false,
          checkStrictly: true
        }" clearable class="!w-[180px]" placeholder="请选择所属部门" />
      </el-form-item>

      <el-form-item label="状态：" prop="status">
        <el-select v-model="form.status" placeholder="请选择状态" clearable class="!w-[180px]">
          <el-option label="启用" :value="1" />
          <el-option label="停用" :value="-1" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" :icon="useRenderIcon(Search)" @click="onSearch">
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar title="岗位列表" @refresh="onSearch">
      <template #buttons>
        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="openDialog('新增')">
          新增岗位
        </el-button>
      </template>
      <template v-slot="{}">
        <pure-table row-key="id" :loading="loading" :columns="columns" :data="dataList" :pagination="pagination"
          :paginationSmall="true" :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }" @selection-change="handleSelectionChange" @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :icon="useRenderIcon(EditPen)"
              @click="openDialog('修改', row)">
              修改
            </el-button>
            <el-popconfirm :title="`是否确认删除岗位名称为${row.positionName}的这条数据`" @confirm="handleDelete(row)">
              <template #reference>
                <el-button class="reset-margin" link type="primary" :icon="useRenderIcon(Delete)">
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style lang="scss" scoped>
.search-form {
  :deep(.el-form-item) {
    margin-bottom: 12px;
  }
}
</style>